import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Question7 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        
        int n = in.nextInt();
        int m = in.nextInt();

        int[][] nums = new int[n][m];

        long[] sumRow = new long[n];
        long[] sumCol = new long[m];
        long tol = 0;

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                nums[i][j] = in.nextInt();
                
                sumRow[i] += nums[i][j];
                sumCol[j] += nums[i][j];

                tol += nums[i][j];
            }
        }

        long s1 = 0;
        long s2 = 0;
        long minm = Integer.MAX_VALUE;

        // 横切
        for (int i = 0; i < n; i++) {
            s1 += sumRow[i];
            s2 = tol - s1;

            minm = Math.min(minm, Math.abs(s1 - s2));
        }

        s1 = 0;
        s2 = 0;

        // 竖切
        for (int i = 0; i < m; i++) {
            s1 += sumCol[i];
            s2 = tol - s1;

            minm = Math.min(minm, Math.abs(s1 - s2));
        }

        System.out.println(minm);
    }
}